/*
 * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.semagia.atomico.server;

import com.semagia.atomico.server.storage.IModifiableStorage;
import com.semagia.atomico.server.storage.IStorage;

/**
 * Thread-safe, immutable context for the server-side of Atomico.
 * 
 * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
 * @version $Rev: 66 $ - $Date: 2010-09-06 15:29:07 +0000 (Mon, 06 Sep 2010) $
 */
public class ServerApplication implements IServerApplication {

    private final IStorage _storage;
    private final IConfiguration _config;

    /**
     * Creates a new instance with the provided storage and configuration.
     *
     * @param storage The storage.
     * @param config The configuration.
     */
    public ServerApplication(final IStorage storage, final IConfiguration config) {
        if (storage == null) {
            throw new IllegalArgumentException("The storage must not be null");
        }
        if (config == null) {
            throw new IllegalArgumentException("The configuration must not be null");
        }
        _config = config;
        _storage = storage;
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.server.IServerApplication#getStorage()
     */
    @Override
    public IStorage getStorage() {
        return _storage;
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.server.IServerApplication#getModifiableStorage()
     */
    @Override
    public IModifiableStorage getModifiableStorage() {
        return _storage.isModifiable() ? (IModifiableStorage) _storage : null;
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.server.IServerApplication#getConfiguration()
     */
    @Override
    public IConfiguration getConfiguration() {
        return _config;
    }

}
